package com.honeycomb.article.dto;

import java.util.Arrays;

public enum ArticleCatagory {
	ALL(-1),
	QUESTION(1),
	FUNNY(2),
	FOOD_SKITTLES(3),
	NEWS(4),
	SUBJECT(5),
	SYSTEM(100);  //系统消息
	
	private int intValue;
	
	private ArticleCatagory(int intValue) {
		this.intValue = intValue;
	}
	
	/**
	 * 根据传入字符串来返回对应的状态类型
	 */
	public static ArticleCatagory getArticleCatagory(String strValue) {
		try {
			ArticleCatagory type = valueOf(strValue);
			return type;
		}
		catch(Exception ex) {
			throw new IllegalArgumentException("Value '" + strValue + "' is not allowed in ArticleCatagory. Only "
					+ Arrays.toString(ArticleCatagory.values()) + " are allowed."
					);
		}
	}
	
	/**
	 * 根据传入INT值来返回对应的状态类型
	 */
	public static ArticleCatagory getArticleCatagory(int intValue) {
		for (ArticleCatagory elem : ArticleCatagory.values()) {
			if (elem.toIntValue() == intValue) {
				return elem;
			}
		}

		throw new IllegalArgumentException("Value '" + intValue
				+ "' is not allowed in ArticleCatagory.");
	}

	/**
	 * 返回int值类型。
	 * @return
	 */
	public int toIntValue() {
		return intValue;
	}
	
}
